<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>设备申请记录</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			
		});
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
        function cheackAll(obj){
            var isCheck = $(obj).is(":checked");

            $("#contentTable").find("input[type='checkbox']").each(function(){
                $(this).prop("checked", isCheck);
            });
        }
        function batchProcesst(flag){
            var msg = "";
            if (flag == 'pass') { msg = "<spring:message code='tips.allpass' />" }
            else if (flag == 'reject') { msg = "<spring:message code='tips.alldismissal' />" }
            else{ msg = "<spring:message code='tips.delall' />" }

            confirmx(msg, function () {
                var equipmentList = "";
                $("#contentTable").find("input[type='checkbox']").each(function () {
                    if ($(this).prop('checked')) {
                        var egId = $(this).attr("id");
                        equipmentList = equipmentList + "'" + egId + "',";
                    }
                });
                $.ajax({
                    type: "POST",
                    url: "${ctx}/equipment/eleEquipment/checkList",
                    data: {equipmentList: equipmentList, flag: flag},
                    datatype: "json",
                    success: function (data) {
                        alertx(data.msg, function () {
                            window.location.reload();
                        });
                    },
                    error: function () {
                        alertx("<spring:message code='tips.contactadmin' />");
                        console.log(e);
                    }
                });
            });
        };
        function resubmit(){
			var currentSelect = $("#delFlag").val();
			if(currentSelect != 3){
				 alertx("<spring:message code='tips.dismissal' />");
				 return;
				}
			
			var groupList = "";
            $("#contentTable").find("input[type='checkbox']").each(function () {
                if ($(this).prop('checked')) {
                    var egId = $(this).attr("id");
                    groupList = groupList + "'" + egId + "',";
                }
            });
            $.ajax({
                type: "POST",
                url: "${ctx}/equipment/eleEquipment/resubmit",
                data: {typeList: groupList},
                datatype: "json",
                success: function (data) {
                    alertx(data.msg, function () {
                        window.location.reload();
                    });
                },
                error: function (e) {
                    alertx("<spring:message code='tips.contactadmin' />");
                    console.log(e);
                }
            });
		};
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/equipment/eleEquipment/applylist"><spring:message code="menu.device.Application_Record"/></a></li>
		
	</ul>

    <div class="control-group" style="margin-bottom:20px;/*background-color:#f5f5f5;*/" >
         
            <input type="button" value="<spring:message code='Batch.deletion'/>" class="btn btn-default btn-lg" onclick="batchProcesst('delete');">
        		<input type="button" value="<spring:message code='common.resubmit'/>" class="btn btn-default btn-lg" onclick="resubmit();">
        
        <form:form id="searchForm" modelAttribute="eleEquipment" action="${ctx}/equipment/eleEquipment/applylist"
                   method="post" class="breadcrumb form-search" style="float:right;padding-bottom:0px;padding-top:0px;">
            <input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
            <input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
            <input name="flag" type="hidden" value="${flag}">
            <input name="isFirst" type="hidden" value="${isFirst}">
            
            <ul class="ul-form">
                <li><label><spring:message code="common.device.id"/>：</label>
                    <form:input path="code" htmlEscape="false" maxlength="200" class="input-medium"/>
                </li>
                <li><label><spring:message code='common.status'/>：</label>
                    <form:select path="delFlag" htmlEscape="false"  class="input-medium">
                        <form:option value="5"><spring:message code="all"/></form:option>
                        <form:option value="0"><spring:message code="approved"/></form:option>
                        <form:option value="1"><spring:message code='common.delete'/></form:option>
                        <form:option value="2"><spring:message code='inapproval'/></form:option>
                        <form:option value="3"><spring:message code="rejected"/></form:option>
                    </form:select>
                </li>
                <li class="btns"><input id="btnSubmit" class="btn btn-primary" type="submit" value="<spring:message code='common.Query'/>"/></li>
                <li class="clearfix"></li>
            </ul>
        </form:form>
    </div>
	<sys:message content="${message}"/>
	<table class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
                <th style="width:40px;text-align:center;"><input type="checkbox" onclick="cheackAll(this)"/></th>
				<th><spring:message code="common.device.id"/></th>
				<!--  <th>型号</th> -->

                <th><spring:message code="common.group.group"/></th>
                <th><spring:message code="common.applicant"/></th>
                <th><spring:message code="common.applicant.time"/></th>
                <th>
                    <c:if test="${flag}">
                        <spring:message code='common.applicant'/>
                    </c:if>
                    <c:if test="${!flag}">
                        <spring:message code='common.approver'/>
                    </c:if>
                </th>
				<th><spring:message code="common.approver.time"/></th>
                <th><spring:message code='audit.state'/></th>
                <th><spring:message code='common.remarks'/></th>
                <th><spring:message code='common.comment'/></th>
			</tr>
		</thead>
		<tbody id="contentTable">
		<c:forEach items="${page.list}" var="eleEquipment">
			<tr>
                <td style="text-align:center;"><input type="checkbox" id="${eleEquipment.id}"/></td>
				<td><a href="${ctx}/equipment/eleEquipment/info?id=${eleEquipment.id}&showtype=2">
					${eleEquipment.code}
				</a></td>
				<!-- <td> ${eleEquipment.type.model} </td>  -->

                <td> ${eleEquipment.office.name} </td>
                <td>${eleEquipment.createBy.name}</td>
                <td><fmt:formatDate value="${eleEquipment.createDate}" pattern="yyyy-MM-dd HH:mm:ss"/></td>                
				<td>${flag?eleEquipment.createBy.name:eleEquipment.checkBy.name} </td>
				<td><fmt:formatDate value="${eleEquipment.checkDate}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
				<td>
                    <c:if test="${eleEquipment.delFlag == '0'}">
                       <spring:message code="approved"/>
                    </c:if>
                    <c:if test="${eleEquipment.delFlag == '1'}">
                        <spring:message code='common.delete'/>
                    </c:if>
                    <c:if test="${eleEquipment.delFlag == '2'}">
                        <spring:message code='inapproval'/>
                    </c:if>
                    <c:if test="${eleEquipment.delFlag == '3'}">
                        <spring:message code="rejected"/>
                    </c:if>
                </td>
                <td> ${eleEquipment.remarks} </td>
                <td> ${eleEquipment.comment} </td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
</body>
</html>